﻿
using Expressions.Compiler.Interfaces;
using Expressions.Compiler;

namespace Excel.Expressions.Compiler
{
    using System;
    using System.Linq.Expressions;
    using System.Collections.Generic;
    using Excel.Expressions.Interfaces;

    public abstract class CellExpression
    {
        private readonly List<CellExpression> _children;

        public abstract double Eval();

        internal void Add(CellExpression expression)
        {
            _children.Add(expression);
        }

        internal void AddRange(IEnumerable<CellExpression> expressions)
        {
            _children.AddRange(expressions);
        }

        protected CellExpression()
        {
            _children = new List<CellExpression>();
        }

        internal IEnumerable<CellExpression> Children
        {
            get
            {
                return _children;
            }
        }

        public static implicit operator double(CellExpression value)
        {
            return value.Eval();
        }
    }
}
